﻿/*
 * Creado por SharpDevelop.
 * Usuario: jfacorro
 * Fecha: 01/06/2010
 * Hora: 16:20
 * 
 * Para cambiar esta plantilla use Herramientas | Opciones | Codificación | Editar Encabezados Estándar
 */
using System;

namespace TimeMaker
{
	/// <summary>
	/// Description of SongManager.
	/// </summary>
	public class SongManager
	{
		private FMOD.System system = null;
		private FMOD.Sound sound = null;
		private FMOD.Channel channel = null;
		private FMOD.RESULT result;
		
		public float Bpm
		{
			get; set;
		}

		public SongManager()
		{
			result = FMOD.Factory.System_Create(ref this.system);
			result = this.system.init(100, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);
		}
		
		public void LoadSong(string filename)
		{
			FMOD.MODE mode = FMOD.MODE.CREATESTREAM | FMOD.MODE.SOFTWARE | FMOD.MODE.OPENONLY;
			result = this.system.createSound(filename, mode, ref this.sound);
			result = this.system.playSound(FMOD.CHANNELINDEX.FREE, this.sound, true, ref this.channel);
			
			this.Bpm = BpmDetection.ExtractBPM(this.sound, this.channel);
		}
		
		public void Play()
		{
			if(this.channel != null)
				this.channel.setPaused(false);
		}
		
		public void Pause()
		{
			if(this.channel != null)
				this.channel.setPaused(true);
		}
	}
}
